<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            left: 0px;
            top: 0px;
            width: 100px;
            height: 100px;
            background: orange;
        }
        span {
            position: absolute;
            left: 500px;
            top: 0px;
            background: black;
            width: 1px;
            height: 100px;
        }
    </style>
</head>
<body>
    <div></div>
    <span></span>


    <script>

        var oDiv = document.getElementsByTagName('div')[0];
        var timer = null;
        oDiv.onclick = function () {
            startMove(this, 500);
        }

        // 越靠近中线， a越小
        function startMove (dom, target) {
            clearInterval(timer);
            var iSpeed = 0;
            var u = 0.9; // 能力损耗系数
            timer = setInterval(function () {
                var a = (target - dom.offsetLeft) / 20;
                iSpeed += a;
                iSpeed = iSpeed * 1;
                //近似把绝对值小于 1 看成是速度为0
                if(Math.abs(iSpeed) < 1 && Math.abs(target - dom.offsetLeft) < 1) {
                    clearInterval(timer);
                    console.log('over');
                    dom.style.left  = target + 'px';
                }else {
                    dom.style.left = dom.offsetLeft + iSpeed + 'px';
                }
            }, 30);
        }


    </script>
</body>
</html>